<!DOCTYPE html>
<html>
  <head>
    <script src="./node_modules/docx/build/index.umd.js"></script>
    <script src="./FileSaver.js"></script>
  </head>

  <body>
    <h1>林地保护监管</h1>
    <h3>请勾选需要的区县，它们将生成在同一份报告中</h3>
    <form id="myForm">
      <label><input type="checkbox" name="cou" value="繁昌区">繁昌区</label><br>
      <label><input type="checkbox" name="cou" value="经开区">经开区</label><br>
      <label><input type="checkbox" name="cou" value="镜湖区">镜湖区</label><br>
      <label><input type="checkbox" name="cou" value="鸠江区">鸠江区</label><br>
      <label><input type="checkbox" name="cou" value="南陵县">南陵县</label><br>
      <label><input type="checkbox" name="cou" value="三山区">三山区</label><br>
      <label><input type="checkbox" name="cou" value="湾沚区">湾沚区</label><br>
      <label><input type="checkbox" name="cou" value="无为市">无为市</label><br>
      <label><input type="checkbox" name="cou" value="弋江区">弋江区</label><br>
    </form>
    <button type="button" id="button1">
        林地保护监管报告下载
    </button>

    <script>
      var arr
      const serveraddress = "http://192.168.3.35:8091/exceltoword/selectLdshape?jcsj=2024Q4"

      var button1 = document.getElementById("button1")
        button1.addEventListener("click", function () {
        var xhr = new XMLHttpRequest()
        xhr.responseType = "json"
        xhr.open("GET", "http://192.168.1.105:8091/exceltoword/selectLdshape?jcsj=2024Q4")
        xhr.send()
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
            arr = xhr.response
            generate(arr)
            console.log(arr)
            }
        }
      })


      function generate(arr) {
        //拆分现状和补充数据
        var xzarr = arr.filter(item => item.bhlx === ' ');
        var bcarr = arr.filter(item => item.bhlx === '补充');
        console.log(xzarr, bcarr);

        var couSums1 = {};       
        // 遍历原始数组，计算每个cou的总和，同时将area和count转换为数字
        xzarr.forEach(item => {
            var cou = item.cou;
            var area = parseFloat(item.area);
            var count = parseFloat(item.count);
            
            if (!(cou in couSums1)) {
                couSums1[cou] = { area: 0, count: 0 };
            }
            couSums1[cou].area += area;
            couSums1[cou].count += count;
        });
          
        // 创建一个新数组来存储结果
        var newData1 = [];
          
        // 遍历原始数组，将每个项添加到新数组中，并在每个cou的最后添加总计项
        xzarr.forEach(item => {
            newData1.push({ ...item }); // 使用{ ...item }创建对象的浅拷贝，以避免直接修改原始数组项
            var cou = item.cou;
            // 检查是否已经添加了该cou的总计项（通过查找tblx为"总计"且cou相同的项）
            var hasTotal = newData1.some(x => x.tblx === "总计" && x.cou === cou);
            if (!hasTotal) {
                var totalItem = {
                    cou: cou,
                    area: couSums1[cou].area.toFixed(2), // 将总和格式化为保留两位小数的字符串
                    tblx: "总计",
                    count: couSums1[cou].count 
                };
                newData1.push(totalItem);
            }
        });
          
        // 按照cou的顺序排序，并确保总计项在每个cou的最后
        var xzarray = [];
        var couOrder1 = [...new Set(arr.map(item => item.cou))].sort((a, b) => a.localeCompare(b));
          
        couOrder1.forEach(cou => {
            var couItems = newData1.filter(item => item.cou === cou);
            var nonTotalItems = couItems.filter(item => item.tblx !== "总计");
            var totalItem = couItems.find(item => item.tblx === "总计");
            
            xzarray.push(...nonTotalItems);
            if (totalItem) {
                xzarray.push(totalItem);
            }
        });
          
        // 打印结果
        console.log(xzarray);

        var couSums2 = {};       
        // 遍历原始数组，计算每个cou的总和，同时将area和count转换为数字
        bcarr.forEach(item => {
            var cou = item.cou;
            var area = parseFloat(item.area);
            var count = parseFloat(item.count);
            
            if (!(cou in couSums2)) {
                couSums2[cou] = { area: 0, count: 0 };
            }
            couSums2[cou].area += area;
            couSums2[cou].count += count;
        });
          
        // 创建一个新数组来存储结果
        var newData2 = [];
          
        // 遍历原始数组，将每个项添加到新数组中，并在每个cou的最后添加总计项
        bcarr.forEach(item => {
            newData2.push({ ...item }); // 使用{ ...item }创建对象的浅拷贝，以避免直接修改原始数组项
            var cou = item.cou;
            // 检查是否已经添加了该cou的总计项（通过查找tblx为"总计"且cou相同的项）
            var hasTotal = newData2.some(x => x.tblx === "总计" && x.cou === cou);
            if (!hasTotal) {
                var totalItem = {
                    cou: cou,
                    area: couSums2[cou].area.toFixed(2), // 将总和格式化为保留两位小数的字符串
                    tblx: "总计",
                    count: couSums2[cou].count 
                };
                newData2.push(totalItem);
            }
        });
          
        // 按照cou的顺序排序，并确保总计项在每个cou的最后
        var bcarray = [];
        var couOrder2 = [...new Set(arr.map(item => item.cou))].sort((a, b) => a.localeCompare(b));
          
        couOrder2.forEach(cou => {
            var couItems = newData2.filter(item => item.cou === cou);
            var nonTotalItems = couItems.filter(item => item.tblx !== "总计");
            var totalItem = couItems.find(item => item.tblx === "总计");
            
            bcarray.push(...nonTotalItems);
            if (totalItem) {
                bcarray.push(totalItem);
            }
        });
          
        // 打印结果
        console.log(bcarray);

        //计算现状和补充总计数据
        var sumcount1 = 0
        var sumarea1 = 0
        var sumcount2 = 0
        var sumarea2 = 0
        xzarr.reduce((accumulator, item) => {  
          sumcount1 += parseFloat(item.count); 
          }, {});
        xzarr.reduce((accumulator, item) => {  
          sumarea1 += parseFloat(item.area); 
          }, {});
        bcarr.reduce((accumulator, item) => {  
          sumcount2 += parseFloat(item.count); 
          }, {});
        bcarr.reduce((accumulator, item) => {  
          sumarea2 += parseFloat(item.area); 
          }, {});
               
        var rows1 = [
            new docx.TableRow({
                children: [
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "县市区" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "图斑类型" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [
                      new docx.Paragraph({ text: "个数" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "面积（亩）" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                ],
            }),
        ]
        xzarray.forEach(item => {  
            rows1.push(new docx.TableRow({  
                children: [  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.cou}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.tblx}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.count}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area).toFixed(2)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                ],  
            }));  
        });
        rows1.push(new docx.TableRow({  
            children: [  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: "总计" })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${sumcount1}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(sumarea1).toFixed(2)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
            ],  
        }));

        var rows2 = [
            new docx.TableRow({
                children: [
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "县市区" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "图斑类型" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [
                      new docx.Paragraph({ text: "个数" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "面积（亩）" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                ],
            }),
        ]
        bcarray.forEach(item => {  
            rows2.push(new docx.TableRow({  
                children: [  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.cou}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.tblx}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.count}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area).toFixed(2)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                ],  
            }));  
        });
        rows2.push(new docx.TableRow({  
            children: [  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: "总计" })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${sumcount2}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(sumarea2).toFixed(2)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
            ],  
        }));

        //3.1所需数据
        var sumcount = sumcount1 + sumcount2;
        var sumarea = sumarea1 + sumarea2;

        var cfarea = 0;
        var jsarea = 0;
        var qtarea = 0;
        
        arr.forEach(item => {
            if (item.tblx === "采伐") {
                cfarea += parseFloat(item.area);
            }
        });
        arr.forEach(item => {
            if (item.tblx === "建设项目使用林地") {
                jsarea += parseFloat(item.area);
            }
        });
        arr.forEach(item => {
            if (item.tblx === "其他") {
                qtarea += parseFloat(item.area);
            }
        });

        var cfpercentage = (cfarea / sumarea) * 100;
        var jspercentage = (jsarea / sumarea) * 100;
        var qtpercentage = (qtarea / sumarea) * 100;
        
        //3.1.1变化图斑所需数据
        var cfarea1 = 0;
        var jsarea1 = 0;
        var qtarea1 = 0;
        
        xzarr.forEach(item => {
            if (item.tblx === "采伐") {
                cfarea1 += parseFloat(item.area);
            }
        });
        xzarr.forEach(item => {
            if (item.tblx === "建设项目使用林地") {
                jsarea1 += parseFloat(item.area);
            }
        });
        xzarr.forEach(item => {
            if (item.tblx === "其他") {
                qtarea1 += parseFloat(item.area);
            }
        });

        var cfpercentage1 = (cfarea1 / sumarea1) * 100;
        var jspercentage1 = (jsarea1 / sumarea1) * 100;
        var qtpercentage1 = (qtarea1 / sumarea1) * 100;
        // console.log(cfpercentage1,jspercentage1,qtpercentage1); 

        var count11 = 0;
        var area11 = 0;
        xzarr.forEach(item => {
            if (item.cou === "镜湖区") {
                count11 += parseFloat(item.count);
                area11 += parseFloat(item.area);
            }
        });
        var percentage11 = (area11 / sumarea1) * 100;
        var count12 = 0;
        var area12 = 0;
        xzarr.forEach(item => {
            if (item.cou === "鸠江区") {
                count12 += parseFloat(item.count);
                area12 += parseFloat(item.area);
            }
        });
        var percentage12 = (area12 / sumarea1) * 100;
        var count13 = 0;
        var area13 = 0;
        xzarr.forEach(item => {
            if (item.cou === "经开区") {
                count13 += parseFloat(item.count);
                area13 += parseFloat(item.area);
            }
        });
        var percentage13 = (area13 / sumarea1) * 100;
        var count14 = 0;
        var area14 = 0;
        xzarr.forEach(item => {
            if (item.cou === "弋江区") {
                count14 += parseFloat(item.count);
                area14 += parseFloat(item.area);
            }
        });
        var percentage14 = (area14 / sumarea1) * 100;
        var count15 = 0;
        var area15 = 0;
        xzarr.forEach(item => {
            if (item.cou === "三山区") {
                count15 += parseFloat(item.count);
                area15 += parseFloat(item.area);
            }
        });
        var percentage15 = (area15 / sumarea1) * 100;
        var count16 = 0;
        var area16 = 0;
        xzarr.forEach(item => {
            if (item.cou === "湾沚区") {
                count16 += parseFloat(item.count);
                area16 += parseFloat(item.area);
            }
        });
        var percentage16 = (area16 / sumarea1) * 100;
        var count17 = 0;
        var area17 = 0;
        xzarr.forEach(item => {
            if (item.cou === "繁昌区") {
                count17 += parseFloat(item.count);
                area17 += parseFloat(item.area);
            }
        });
        var percentage17 = (area17 / sumarea1) * 100;
        var count18 = 0;
        var area18 = 0;
        xzarr.forEach(item => {
            if (item.cou === "南陵县") {
                count18 += parseFloat(item.count);
                area18 += parseFloat(item.area);
            }
        });
        var percentage18 = (area18 / sumarea1) * 100;
        var count19 = 0;
        var area19 = 0;
        xzarr.forEach(item => {
            if (item.cou === "无为市") {
                count19 += parseFloat(item.count);
                area19 += parseFloat(item.area);
            }
        });
        var percentage19 = (area19 / sumarea1) * 100;
        
        //3.1.2补充图斑所需数据
        var cfarea2 = 0;
        var jsarea2 = 0;
        var qtarea2 = 0;
        
        bcarr.forEach(item => {
            if (item.tblx === "采伐") {
                cfarea2 += parseFloat(item.area);
            }
        });
        bcarr.forEach(item => {
            if (item.tblx === "建设项目使用林地") {
                jsarea2 += parseFloat(item.area);
            }
        });
        bcarr.forEach(item => {
            if (item.tblx === "其他") {
                qtarea2 += parseFloat(item.area);
            }
        });

        var cfpercentage2 = (cfarea2 / sumarea2) * 100;
        var jspercentage2 = (jsarea2 / sumarea2) * 100;
        var qtpercentage2 = (qtarea2 / sumarea2) * 100;
        
        var count21 = 0;
        var area21 = 0;
        bcarr.forEach(item => {
            if (item.cou === "镜湖区") {
                count21 += parseFloat(item.count);
                area21 += parseFloat(item.area);
            }
        });
        var percentage21 = (area21 / sumarea2) * 100;
        var count22 = 0;
        var area22 = 0;
        bcarr.forEach(item => {
            if (item.cou === "鸠江区") {
                count22 += parseFloat(item.count);
                area22 += parseFloat(item.area);
            }
        });
        var percentage22 = (area22 / sumarea2) * 100;
        var count23 = 0;
        var area23 = 0;
        bcarr.forEach(item => {
            if (item.cou === "经开区") {
                count23 += parseFloat(item.count);
                area23 += parseFloat(item.area);
            }
        });
        var percentage23 = (area23 / sumarea2) * 100;
        var count24 = 0;
        var area24 = 0;
        bcarr.forEach(item => {
            if (item.cou === "弋江区") {
                count24 += parseFloat(item.count);
                area24 += parseFloat(item.area);
            }
        });
        var percentage24 = (area24 / sumarea2) * 100;
        var count25 = 0;
        var area25 = 0;
        bcarr.forEach(item => {
            if (item.cou === "三山区") {
                count25 += parseFloat(item.count);
                area25 += parseFloat(item.area);
            }
        });
        var percentage25 = (area25 / sumarea2) * 100;
        var count26 = 0;
        var area26 = 0;
        bcarr.forEach(item => {
            if (item.cou === "湾沚区") {
                count26 += parseFloat(item.count);
                area26 += parseFloat(item.area);
            }
        });
        var percentage26 = (area26 / sumarea2) * 100;
        var count27 = 0;
        var area27 = 0;
        bcarr.forEach(item => {
            if (item.cou === "繁昌区") {
                count27 += parseFloat(item.count);
                area27 += parseFloat(item.area);
            }
        });
        var percentage27 = (area27 / sumarea2) * 100;
        var count28 = 0;
        var area28 = 0;
        bcarr.forEach(item => {
            if (item.cou === "南陵县") {
                count28 += parseFloat(item.count);
                area28 += parseFloat(item.area);
            }
        });
        var percentage28 = (area28 / sumarea2) * 100;
        var count29 = 0;
        var area29 = 0;
        bcarr.forEach(item => {
            if (item.cou === "无为市") {
                count29 += parseFloat(item.count);
                area29 += parseFloat(item.area);
            }
        });
        var percentage29 = (area29 / sumarea2) * 100;

        var doc = new docx.Document({
          sections: [
            {
              children: [
                new docx.Paragraph({
                  text: "3.1成果分析",
                  heading: docx.HeadingLevel.HEADING_1,
                }),
                new docx.Paragraph({
                  text: `利用2024年第四季度芜湖市0.5米分辨率遥感影像对全市范围内的林地现状进行监测摸底，提取2023年变更调查林地（扣除城镇村及工矿用地）范围内植被被采伐、建设项目占用及其他占用的图斑。`,
                }),
                new docx.Paragraph({
                  text: `经过解译分析，芜湖市林地范围内一共监测未种植林地图斑${sumcount}个，面积${parseFloat(sumarea).toFixed(2)}亩，其中采伐图斑面积${parseFloat(cfarea).toFixed(2)}亩，占比高达${parseFloat(cfpercentage).toFixed(2)}%；建设项目使用林地图斑面积${parseFloat(jsarea).toFixed(2)}亩，占比${parseFloat(jspercentage).toFixed(2)}%；其他占用林地图斑面积${parseFloat(qtarea).toFixed(2)}亩，占比高达${parseFloat(qtpercentage).toFixed(2)}%。`,
                }),
                new docx.Paragraph({
                  text: "3.1.1变化图斑",
                  heading: docx.HeadingLevel.HEADING_1,
                }),
                new docx.Paragraph({
                  text: `经过解译分析，芜湖市林地范围内一共监测未种植林地图斑变化图斑${sumcount1}个，面积${parseFloat(sumarea1).toFixed(2)}亩，其中采伐图斑面积${parseFloat(cfarea1).toFixed(2)}亩，占比${parseFloat(cfpercentage1).toFixed(2)}%；建设项目使用林地图斑面积${parseFloat(jsarea1).toFixed(2)}亩，占比${parseFloat(jspercentage1).toFixed(2)}%；其他占用林地图斑面积${parseFloat(qtarea1).toFixed(2)}亩，占比${parseFloat(qtpercentage1).toFixed(2)}%。`,
                }),
                new docx.Paragraph({
                  text: `各县市区情况为镜湖区${count11}个，面积${parseFloat(area11).toFixed(2)}亩,面积占比${parseFloat(percentage11).toFixed(2)}%；鸠江区${count12}个，面积${parseFloat(area12).toFixed(2)}亩,面积占比${parseFloat(percentage12).toFixed(2)}%；经开区${count13}个，面积${parseFloat(area13).toFixed(2)}亩,面积占比${parseFloat(percentage13).toFixed(2)}%；弋江区${count14}个，面积${parseFloat(area14).toFixed(2)}亩,面积占比${parseFloat(percentage14).toFixed(2)}%；三山区${count15}个，面积${parseFloat(area15).toFixed(2)}亩,面积占比${parseFloat(percentage15).toFixed(2)}%；湾沚区${count16}个，面积${parseFloat(area16).toFixed(2)}亩,面积占比${parseFloat(percentage16).toFixed(2)}%；繁昌区${count17}个，面积${parseFloat(area17).toFixed(2)}亩,面积占比${parseFloat(percentage17).toFixed(2)}%；南陵县${count18}个，面积${parseFloat(area18).toFixed(2)}亩,面积占比${parseFloat(percentage18).toFixed(2)}%；无为市${count19}个，面积${parseFloat(area19).toFixed(2)}亩,面积占比${parseFloat(percentage19).toFixed(2)}%。`,
                }),
                new docx.Paragraph({
                  text: "表3-1 芜湖市2024年第四季度林地资源现状监测图斑面积统计表（单位：亩）",
                  heading: docx.HeadingLevel.HEADING_3,
                  alignment: docx.AlignmentType.CENTER,
                }),
                new docx.Table({
                  rows: rows1
                }),
                new docx.Paragraph({
                  text: "3.1.2补充图斑",
                  heading: docx.HeadingLevel.HEADING_1,
                }),
                new docx.Paragraph({
                  text: `经过解译分析，芜湖市林地范围内共监测未种植林地存量图斑${sumcount2}个，面积${parseFloat(sumarea2).toFixed(2)}亩，其中采伐图斑面积${parseFloat(cfarea2).toFixed(2)}亩，占比${parseFloat(cfpercentage2).toFixed(2)}%；建设项目使用林地图斑面积${parseFloat(jsarea2).toFixed(2)}亩，占比${parseFloat(jspercentage2).toFixed(2)}%；其他占用林地图斑面积${parseFloat(qtarea2).toFixed(2)}亩，占比${parseFloat(qtpercentage2).toFixed(2)}%。`,
                }),
                new docx.Paragraph({
                  text: `各县市区情况为镜湖区${count21}个，面积${parseFloat(area21).toFixed(2)}亩,面积占比${parseFloat(percentage21).toFixed(2)}%；鸠江区${count22}个，面积${parseFloat(area22).toFixed(2)}亩,面积占比${parseFloat(percentage22).toFixed(2)}%；经开区${count23}个，面积${parseFloat(area23).toFixed(2)}亩,面积占比${parseFloat(percentage23).toFixed(2)}%；弋江区${count24}个，面积${parseFloat(area24).toFixed(2)}亩,面积占比${parseFloat(percentage24).toFixed(2)}%；三山区${count25}个，面积${parseFloat(area25).toFixed(2)}亩,面积占比${parseFloat(percentage25).toFixed(2)}%；湾沚区${count26}个，面积${parseFloat(area26).toFixed(2)}亩,面积占比${parseFloat(percentage26).toFixed(2)}%；繁昌区${count27}个，面积${parseFloat(area27).toFixed(2)}亩,面积占比${parseFloat(percentage27).toFixed(2)}%；南陵县${count28}个，面积${parseFloat(area28).toFixed(2)}亩,面积占比${parseFloat(percentage28).toFixed(2)}%；无为市${count29}个，面积${parseFloat(area29).toFixed(2)}亩,面积占比${parseFloat(percentage29).toFixed(2)}%。`,
                }),
                new docx.Paragraph({
                  text: "表3-2 芜湖市2024年第四季度林地资源现状监测补充图斑面积统计表（单位：亩）",
                  heading: docx.HeadingLevel.HEADING_3,
                  alignment: docx.AlignmentType.CENTER,
                }),
                new docx.Table({
                  rows: rows2
                }),
              ],
            },
          ],
        });


        docx.Packer.toBlob(doc).then((blob) => {
            console.log(blob);
            saveAs(blob, "林地保护监管报告.docx");
            console.log("Document created successfully");
          });
        // var button1 = document.getElementById("button1")
        // button1.addEventListener("click", function () {
        //     docx.Packer.toBlob(doc).then((blob) => {
        //     console.log(blob);
        //     saveAs(blob, "林地保护监管报告.docx");
        //     console.log("Document created successfully");
        //   });
        // })
      }
    </script>
  </body>
</html>
